Skip to content

Create wmin/wmax on the device of the given weights - #837

Merged
Hananel-Hazan merged 1 commit into
masterfrom
fix-wmin-device
Nov 10, 2026
Merged

Hananel-Hazan merged 1 commit into
masterfrom
fix-wmin-device

Conversation

@Hananel-Hazan

Copy link
Copy Markdown
Collaborator

What this changes and why

A connection built from weights already on a GPU (Connection(..., w=w_cuda, wmin=0.0, wmax=1.0))
failed in its constructor with Expected all tensors to be on the same device, but got min is on cpu.
AbstractConnection.__init__ always created wmin and wmax on the CPU, and the subclass
constructors clamp the given w against them. The bounds are now created on the device of the
given w. Without w the weights start on the CPU, and so do the bounds, as before.
Reported on Intel XPU (Aurora); the same error happens on CUDA.

Casting the bounds to float avoids the error only for single-value bounds; per-weight bounds
(a tensor the size of w, which the docstring allows) cannot be cast. This fix covers both.

Checklist

  • I ran poetry run pytest locally and it passed. (644 passed, on a machine with CUDA)
  • If I fixed a bug, this test fails on master and passes with my change
    (checked by the bug-test check):
    test/network/test_connections.py::test_connection_from_gpu_weights_clamps_and_learns_on_gpu
    It needs CUDA, so on CI (no GPU) it is skipped and bug-test cannot see it. On a CUDA
    machine both parameter cases fail on master with the device error and pass with the fix.
  • I did not remove tests, remove checks, add skips or xfails, or widen tolerances.
    The new GPU test carries skipif(not torch.cuda.is_available()), like
    test_windows_and_maxpool_state_stay_on_gpu in the same file.
  • If I changed a formula: not applicable.
  • Does this change simulated results (spikes, voltages, traces, weights)?
    - [x] No. Only the device of the bounds changes, and only when w is given.
  • Did any of these files change? No.
  • I added an entry to the Unreleased section of CHANGELOG.md.

AI assistance

  • No AI tools were used.
  • AI tools were used, and I (a human) have read every changed line, run the tests myself, and can explain the change in my own words.

Tools used and for which parts: Claude Code reproduced the bug, wrote the fix, the tests and the
changelog entry.

Not in this pull request

Conv1dConnection, Conv2dConnection, Conv3dConnection and MeanFieldConnection clamp a given
w only when a bound is infinite ((self.wmin == -inf).any() or (self.wmax == inf).any()), the
reverse of Connection (!=). With finite bounds a given w is never clamped. Fixing it changes
results for anyone passing out-of-range weights, so it belongs in its own pull request.

A connection built from GPU weights failed in its constructor's clamp
("Expected all tensors to be on the same device"): AbstractConnection
always created the bounds on the CPU. They now follow w's device; without
w they stay on the CPU as before. Single-value and per-weight bounds both
work. No change in results.

Test: test_connection_from_gpu_weights_clamps_and_learns_on_gpu fails on
master on a CUDA machine and passes with the fix (CI has no GPU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hananel-Hazan Hananel-Hazan added tests-changed-ok Maintainer reviewed every item the weakened-tests check listed no-bug-test Maintainer: not a bug fix (refactor/speed-up); skips the bug-test check labels Nov 10, 2026
@Hananel-Hazan
Hananel-Hazan merged commit 3a4cdfa into master Nov 10, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-bug-test Maintainer: not a bug fix (refactor/speed-up); skips the bug-test check tests-changed-ok Maintainer reviewed every item the weakened-tests check listed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant